<?php
namespace app\admin\model;

class Guanli extends BaseModel
{
    /**
     * 管理显示
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getGuanli()
    {
        $guan = self::join('Auth_group', 'Auth_group.id=jc_guanli.gid')
            ->alias('g')
            ->field('Auth_group.jname,Auth_group.id,g.phone,g.gname,g.state,g.gid,g.head_portrait,g.id as zid')
            ->select();
        return $guan;
    }

    /**修改页面显示
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function updata()
    {
        $id = input('id');
        $guan = self::alias('g')
            ->join('Auth_group', 'Auth_group.id=g.gid')
            ->where('jc_guanli.id',$id)
            ->field('Auth_group.jname,Auth_group.id,g.phone,g.state,g.gname,g.gid,g.head_portrait,g.id as zid')
            ->find();
        return $guan;
    }

    /**
     * 根据条件修改
     * @param $where
     * @param $data
     * @return bool
     */
    public function updateByWhere($where,$data)
    {
        $result = self::where($where)->update($data);
        if($result===false){
            return 3;
        } else{
            return 1;
        }
    }

    /**
     * 修改表连接下的某个字段的值
     * @param $id
     * @param $data
     * @return int
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function updateByjin($id,$data)
    {
        $result = self::where('jc_guanli.id',$id)->update($data);
        if($result===false){
            return 3;
        } else{
            return 1;
        }
    }

    /**
     * 删除指定数据
     * @param $where
     * @return int
     */
    public function deleteByWhere($where)
    {
        return $this->where($where)->delete();
    }
      public function modPassWord(){
        if(request()->isAjax())
        {
            $id=input('id');
            //echo $id.'1';die;
            $data = input('repwd');
            $res = db('guanli')
                ->where('id', $id)
                ->update(['pwd' => md5($data)]);
            if ($res)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else
        {
            return view('modpassword');
        }
    }
}